

#include <iostream>
using namespace std;

#include <list>

template <class Containers>
void Print(const Containers& con)
{
	for (auto& c : con)
	{
		cout << c << " ";
	}
	cout << endl;
}

void Test1()
{
	//list<int> l1 = { 1, 2, 3, 4, 5};
	//list<int> l1(5, 1);
	//list<int> l1;
	int a[] = { 1, 2, 3, 4, 5 };
	list<int> l1(a, a+ sizeof(a)/sizeof(a[0]));

	Print(l1);
	cout << l1.size() << endl;
	cout << l1.empty() << endl;

	l1.clear();
	cout << l1.size() << endl;
	cout << l1.empty() << endl;

	l1.push_front(2);
	l1.push_front(1);
	l1.push_back(3);
	l1.push_back(4);
	l1.insert(l1.end(), 5);
	l1.insert(l1.end(), a, a + sizeof(a) / sizeof(a[0]));
	Print(l1);

	l1.pop_back();
	l1.erase(--l1.end());
	Print(l1);

	list<int>::iterator pos = find(l1.begin(), l1.end(), 3);
	if (pos != l1.end())
	{
		l1.erase(pos, l1.end());
	}
	Print(l1);
}

void Test2()
{
	list<int> l1 = { 1, 2, 3, 4, 5 };
	list<int> l2 = { 6, 7, 8 };

	/*l1.splice(l1.end(), l2);
	Print(l1);
	Print(l2);*/

	/*list<int>::iterator pos = find(l1.begin(), l1.end(), 3);
	if (pos != l1.end())
	{
		l1.splice(pos, l2, ++l2.begin());
	}
	Print(l1);
	Print(l2);*/

	list<int>::iterator pos = find(l1.begin(), l1.end(), 5);
	if (pos != l1.end())
	{
		l1.splice(pos, l2, l2.begin(), --l2.end());
	}
	Print(l1);
	Print(l2);
}

struct is_odd
{
	bool operator()(const int& val)
	{
		return 1 != val % 2;
	}
};

struct func
{
	bool operator()(const int& l, const int& r)
	{
		/*if (l < r)
			return false;
		else
			return true;*/

		return l + r < 5;
	}
};

void Test3()
{
	list<int> l1 = { 1, 2, 2, 2, 3, 4, 5 };

	/*Print(l1);
	l1.remove(2);
	Print(l1);

	l1.remove_if(is_odd());
	Print(l1);*/

	/*Print(l1);
	l1.unique();
	Print(l1);*/

	Print(l1);
	l1.unique(func());
	Print(l1);

}

template<class T>
struct MySort
{
	bool operator()(const T& fir, const T& sec)
	{
		return fir < sec;
	}
};

void Test4()
{
	list<int> l1 = { 2, 1, 3, 5};
	list<int> l2 = { 8, 4, 6, 9, 7 };

	Print(l1);
	Print(l2);

	l1.sort(MySort<int>());
	l2.sort();
	//l1.merge(l2);
	l1.merge(l2, MySort<int>());

	Print(l1);
	Print(l2);

	l1.reverse();
	Print(l1);

	cout << "///////////////////////\n";

	l1.swap(l2);
	Print(l1);
	Print(l2);
}

int main()
{
	//Test1();
	//Test2();
	//Test3();
	Test4();

	return 0;
}